package leetcode.ge100;

import java.util.HashSet;
import java.util.Set;

class Solution_142 {

	public static void main(String[] args) {
	}

	public ListNode detectCycle(ListNode head) {
		Set<ListNode> set = new HashSet<ListNode>();
		while (head != null) {
			if (set.add(head)) {
				head = head.next;
			} else {
				return head.next;
			}
		}
		return null;
	}

}
